```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java线程控制：wait()与sleep()方法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background-color: #2d3748;
            border-radius: 0.5rem;
            overflow: hidden;
        }
        .code-header {
            background-color: #1a202c;
            color: #e2e8f0;
            padding: 0.5rem 1rem;
            font-family: monospace;
            border-top-left-radius: 0.5rem;
            border-top-right-radius: 0.5rem;
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 1;
            margin-right: 0.5rem;
            margin-top: 0.5rem;
            color: #4f46e5;
            font-weight: bold;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">Java线程控制：<span class="text-yellow-300">wait()</span>与<span class="text-yellow-300">sleep()</span></h1>
            <p class="text-xl md:text-2xl mb-8 max-w-3xl mx-auto leading-relaxed">深入理解Java中两种线程控制方法的区别与应用场景</p>
            <div class="flex justify-center space-x-4">
                <div class="bg-white text-purple-700 px-6 py-3 rounded-full font-semibold inline-flex items-center">
                    <i class="fas fa-book mr-2"></i> 学习指南
                </div>
                <div class="bg-opacity-20 bg-white px-6 py-3 rounded-full font-semibold inline-flex items-center hover:bg-opacity-30 transition">
                    <i class="fas fa-code mr-2"></i> 代码示例
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <p class="text-gray-700 text-lg leading-relaxed drop-cap">
                <span class="text-gray-900 font-medium">wait()</span> 和 <span class="text-gray-900 font-medium">sleep()</span> 是 Java 中用于线程控制的两个不同方法，它们用于不同的目的，并且有各自的特性和用法。本文将深入解析这两种方法的区别，并通过可视化图表和代码示例展示它们的核心特性。
            </p>
        </section>

        <!-- Comparison Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 font-serif border-b pb-2">核心区别对比</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <!-- wait() Card -->
                <div class="bg-white p-6 rounded-xl shadow-lg card-hover border-l-4 border-purple-600">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 p-3 rounded-full mr-4">
                            <i class="fas fa-handshake text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">wait() 方法</h3>
                    </div>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span><strong>目的：</strong>用于线程间通信和协调，使线程等待直到被通知</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span><strong>所在类：</strong>java.lang.Object</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span><strong>使用条件：</strong>必须在同步块/方法中调用，并释放锁</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span><strong>异常：</strong>抛出 InterruptedException</span>
                        </li>
                    </ul>
                </div>
                
                <!-- sleep() Card -->
                <div class="bg-white p-6 rounded-xl shadow-lg card-hover border-l-4 border-blue-600">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-clock text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">sleep() 方法</h3>
                    </div>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span><strong>目的：</strong>暂停线程执行指定时间，不涉及线程协调</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span><strong>所在类：</strong>java.lang.Thread</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span><strong>使用条件：</strong>可在任何位置调用，不释放锁</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span><strong>异常：</strong>抛出 InterruptedException</span>
                        </li>
                    </ul>
                </div>
            </div>

            <!-- Visualization -->
            <div class="bg-white p-6 rounded-xl shadow-lg mb-8">
                <h3 class="text-xl font-bold mb-4 text-gray-800 font-serif">方法调用流程对比</h3>
                <div class="mermaid">
                    graph TD
                        subgraph wait()
                            A[获取对象锁] --> B[调用wait()]
                            B --> C[释放锁]
                            C --> D[等待notify/notifyAll]
                            D --> E[重新获取锁]
                            E --> F[继续执行]
                        end
                        
                        subgraph sleep()
                            G[调用sleep()] --> H[暂停执行]
                            H --> I[不释放锁]
                            I --> J[时间到继续执行]
                        end
                </div>
            </div>
        </section>

        <!-- Detailed Explanation -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 font-serif border-b pb-2">详细解析</h2>
            
            <div class="space-y-12">
                <!-- Purpose Section -->
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-700 font-serif">1. 目的</h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h4 class="font-bold text-lg text-purple-700 mb-3 flex items-center">
                                <i class="fas fa-handshake mr-2"></i> wait()
                            </h4>
                            <p class="text-gray-700 leading-relaxed"><strong>目的：</strong><code>wait()</code> 方法用于线程之间的通信和协调。它使当前线程等待，直到其他线程调用 <code>notify()</code> 或 <code>notifyAll()</code> 方法通知它继续执行。</p>
                            <p class="text-gray-700 leading-relaxed mt-2"><strong>应用场景：</strong>常用于实现线程之间的等待和通知机制，例如生产者-消费者模式。</p>
                        </div>
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h4 class="font-bold text-lg text-blue-700 mb-3 flex items-center">
                                <i class="fas fa-clock mr-2"></i> sleep()
                            </h4>
                            <p class="text-gray-700 leading-relaxed"><strong>目的：</strong><code>sleep()</code> 方法使当前线程暂停执行指定的时间。这是一种让线程在不占用 CPU 的情况下暂停执行的方式。</p>
                            <p class="text-gray-700 leading-relaxed mt-2"><strong>应用场景：</strong>常用于暂停线程的执行或模拟长时间的操作，通常不涉及线程间的协调。</p>
                        </div>
                    </div>
                </div>
                
                <!-- Class Section -->
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-700 font-serif">2. 所在类</h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h4 class="font-bold text-lg text-purple-700 mb-3">wait()</h4>
                            <p class="text-gray-700 leading-relaxed"><strong>所在的类：</strong><code>java.lang.Object</code>，<code>wait()</code> 方法是 <code>Object</code> 类的一部分，因为它用于线程对某个对象的监视器（锁）的操作。任何对象的监视器都可以调用 <code>wait()</code>，<code>notify()</code>，或 <code>notifyAll()</code>。</p>
                        </div>
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h4 class="font-bold text-lg text-blue-700 mb-3">sleep()</h4>
                            <p class="text-gray-700 leading-relaxed"><strong>所在的类：</strong><code>java.lang.Thread</code>，<strong>说明：</strong><code>sleep()</code> 方法是 <code>Thread</code> 类的一部分，它是用于控制当前线程的休眠。</p>
                        </div>
                    </div>
                </div>
                
                <!-- Usage Conditions Section -->
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-700 font-serif">3. 使用条件</h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h4 class="font-bold text-lg text-purple-700 mb-3">wait()</h4>
                            <ul class="space-y-2 text-gray-700">
                                <li><strong>条件：</strong>必须在同步块或同步方法中调用。调用 <code>wait()</code> 的线程必须持有该对象的监视器（锁）。</li>
                                <li><strong>释放锁：</strong>调用 <code>wait()</code> 方法后，线程会释放当前持有的锁，并进入等待状态。</li>
                                <li><strong>恢复执行：</strong>线程会在被调用 <code>notify()</code> 或 <code>notifyAll()</code> 方法后被唤醒，或者在指定的超时后被唤醒（如果使用超时版本）。</li>
                            </ul>
                        </div>
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h4 class="font-bold text-lg text-blue-700 mb-3">sleep()</h4>
                            <ul class="space-y-2 text-gray-700">
                                <li><strong>条件：</strong>不需要在同步块或同步方法中调用。<code>sleep()</code> 方法可以在任何地方调用。</li>
                                <li><strong>释放锁：</strong>调用 <code>sleep()</code> 不会释放任何锁，因为它不涉及监视器。</li>
                                <li><strong>恢复执行：</strong>线程在指定的时间后自动恢复执行。</li>
                            </ul>
                        </div>
                    </div>
                </div>
                
                <!-- Exception Handling Section -->
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-700 font-serif">4. 异常处理</h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h4 class="font-bold text-lg text-purple-700 mb-3">wait()</h4>
                            <p class="text-gray-700 leading-relaxed">抛出 <code>InterruptedException</code> 异常，当线程在等待过程中被中断时会发生。</p>
                        </div>
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h4 class="font-bold text-lg text-blue-700 mb-3">sleep()</h4>
                            <p class="text-gray-700 leading-relaxed">抛出 <code>InterruptedException</code> 异常，当线程在休眠过程中被中断时会发生。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Examples -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 font-serif border-b pb-2">代码示例</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- wait() Example -->
                <div>
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 p-2 rounded-full mr-3">
                            <i class="fas fa-code text-purple-600"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">wait() 方法示例</h3>
                    </div>
                    <div class="code-block">
                        <div class="code-header flex justify-between items-center">
                            <span>WaitNotifyDemo.java</span>
                            <button class="text-xs bg-blue-500 px-2 py-1 rounded hover:bg-blue-600 transition">复制代码</button>
                        </div>
                        <pre class="p-4 text-gray-100 overflow-x-auto"><code>public class WaitNotifyDemo {
    private static final Object lock = new Object();
    
    public static void main(String[] args) {
        Thread producer = new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println("生产者线程正在等待...");
                    lock.wait(); // 等待通知
                    System.out.println("生产者线程已被通知");
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        });

        Thread notifier = new Thread(() -> {
            synchronized (lock) {
                try {
                    Thread.sleep(2000); // 模拟长时间操作
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
                System.out.println("通知者线程发出通知");
                lock.notify(); // 发出通知
            }
        });

        producer.start();
        notifier.start();
    }
}</code></pre>
                    </div>
                </div>
                
                <!-- sleep() Example -->
                <div>
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-2 rounded-full mr-3">
                            <i class="fas fa-code text-blue-600"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">sleep() 方法示例</h3>
                    </div>
                    <div class="code-block">
                        <div class="code-header flex justify-between items-center">
                            <span>SleepDemo.java</span>
                            <button class="text-xs bg-blue-500 px-2 py-1 rounded hover:bg-blue-600 transition">复制代码</button>
                        </div>
                        <pre class="p-4 text-gray-100 overflow-x-auto"><code>public class SleepDemo {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            System.out.println("线程开始休眠");
            try {
                Thread.sleep(2000); // 休眠 2000 毫秒
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            System.out.println("线程休眠结束");
        });

        thread.start();
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="bg-blue-50 p-8 rounded-xl border border-blue-200 mb-16">
            <h2 class="text-2xl font-bold mb-6 text-blue-800 font-serif">关键总结</h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div>
                    <h3 class="font-bold text-lg text-blue-700 mb-3">何时使用 wait()</h3>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>需要线程间协调通信时</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>实现生产者-消费者模式</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>需要释放锁并等待通知</span>
                        </li>
                    </ul>
                </div>
                <div>
                    <h3 class="font-bold text-lg text-blue-700 mb-3">何时使用 sleep()</h3>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>需要暂停线程执行指定时间</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>模拟耗时操作或延迟</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>不需要线程间协调时</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">专注技术分享与学习</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition duration-300 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // Add copy functionality to code blocks
        document.querySelectorAll('.code-header button').forEach(button => {
            button.addEventListener('click', () => {
                const codeBlock = button.parentElement.nextElementSibling;
                const code = codeBlock.textContent;
                navigator.clipboard.writeText(code).then(() => {
                    button.textContent = '已复制!';
                    setTimeout(() => {
                        button.textContent = '复制代码';
                    }, 2000);
                });
            });
        });
    </script>
</body>
</html>
```